package com.hxq.chatdemo.controller;

import com.hxq.chatdemo.domain.dto.SendMsgDTO;
import com.hxq.chatdemo.service.WebSocketService;
import io.netty.channel.Channel;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/chat")
@RequiredArgsConstructor
public class ChatController {

    private final WebSocketService webSocketService;

    @PostMapping("sendMsg")
    public void sendMsg(@RequestBody SendMsgDTO dto){
        webSocketService.sendMsg(dto.getMsg());
    }

    @GetMapping("getChannels")
    public Map<Channel, String> getChannels(){
        return webSocketService.getChannels();
    }
}
